<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from './mixins/resize'
import axios from "axios";
import {checkStatus, listEvent} from "@/api/volunteer/event";
import {listType} from "@/api/volunteer/type";

const animationDuration = 6000

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default:'350px'
    }
  },
  data() {
    return {
      chart: null,
      dataStatus:[],
      dataNum:[],
      allData: [
        {
          value:null,
          name:null
        }
      ],
      yData:[],
      yValue:[]
    }
  },

  mounted() {
    this.$nextTick(() => {
      listEvent().then((response)=>{
        for(let i=0;i<3;i++){
          this.dataNum[i]=response.rows.map((obj)=>{return obj.eventCheck}).filter((item)=>{return item==i}).length
        }
      checkStatus().then((response)=>{
        const arr=response.rows.map((obj)=>{return obj.checkName})
        for(let j=0;j<this.dataNum.length;j++){
          this.allData.push({value: this.dataNum[j],name: arr[j]})
        }
        this.yData=this.allData.slice(1)
        this.initChart()
      })
      })
      }
    )},
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')
      const option = {
        tooltip: {
          trigger: 'item',
        },
        legend: {
          top: '5%',
          left: 'center'
        },
        series: [
          {
            name: '活动个数',
            type: 'pie',
            radius: ['40%', '70%'],
            avoidLabelOverlap: false,
            label: {
              show: false,
              position: 'center'
            },
            emphasis: {
              label: {
                show: true,
                fontSize: '40',
                fontWeight: 'bold'
              }
            },
            labelLine: {
              show: false
            },
            data: this.yData
          }
        ]
      };
      this.chart.setOption(option)
    },
  }
}
</script>
